<script>
function loadScript(url) {
  return new Promise((resolve, reject) => {
    const script = document.createElement('script')
    script.src=url
    script.onload = () => resolve()
    script.onerror = () => reject(new Error('脚本载入失败'+url))
    document.head.append(script)
  })
}
loadScript('./fn.js')
  .then(() => fn())
  .catch(e => console.log(e))
// fn()

</script>